package com.common.controller;

import java.awt.Color;
import java.awt.Font;
import java.awt.image.ImageFilter;

import com.jhlabs.image.CrystalizeFilter;
import com.jhlabs.image.RippleFilter;
import com.octo.captcha.component.image.backgroundgenerator.BackgroundGenerator;
import com.octo.captcha.component.image.backgroundgenerator.UniColorBackgroundGenerator;
import com.octo.captcha.component.image.deformation.ImageDeformation;
import com.octo.captcha.component.image.deformation.ImageDeformationByFilters;
import com.octo.captcha.component.image.fontgenerator.FontGenerator;
import com.octo.captcha.component.image.fontgenerator.RandomFontGenerator;
import com.octo.captcha.component.image.textpaster.BaffleRandomTextPaster;
import com.octo.captcha.component.image.textpaster.TextPaster;
import com.octo.captcha.component.image.wordtoimage.DeformedComposedWordToImage;
import com.octo.captcha.component.image.wordtoimage.WordToImage;
import com.octo.captcha.component.word.FileDictionary;
import com.octo.captcha.component.word.wordgenerator.DictionaryWordGenerator;
import com.octo.captcha.component.word.wordgenerator.WordGenerator;
import com.octo.captcha.engine.image.ListImageCaptchaEngine;
import com.octo.captcha.image.gimpy.GimpyFactory;

public class CaptchaEngineEx extends ListImageCaptchaEngine {
	protected void buildInitialFactories() {

		RippleFilter rippleBack = new RippleFilter();
		RippleFilter ripple = new RippleFilter();

		CrystalizeFilter crystal = new CrystalizeFilter();

		ripple.setWaveType(3);
		ripple.setXAmplitude(3.0D);
		ripple.setYAmplitude(3.0D);
		ripple.setXWavelength(20.0D);
		ripple.setYWavelength(10.0D);
		ripple.setEdgeAction(1);

		rippleBack.setWaveType(3);
		rippleBack.setXAmplitude(5.0D);
		rippleBack.setYAmplitude(5.0D);
		rippleBack.setXWavelength(10.0D);
		rippleBack.setYWavelength(10.0D);
		rippleBack.setEdgeAction(1);

		crystal.setScale(0.5D);
		crystal.setGridType(0);
		crystal.setFadeEdges(false);
		crystal.setEdgeThickness(0.2000000029802322D);
		crystal.setRandomness(0.1000000014901161D);

		ImageDeformation rippleDef = new ImageDeformationByFilters(
				new ImageFilter[] { ripple });

		ImageDeformation rippleDefBack = new ImageDeformationByFilters(
				new ImageFilter[] { rippleBack });

		ImageDeformation cristalDef = new ImageDeformationByFilters(
				new ImageFilter[] { crystal });


		WordGenerator words = new DictionaryWordGenerator(new FileDictionary("toddlist"));

		TextPaster paster = new BaffleRandomTextPaster(new Integer(5),new Integer(8), Color.black, new Integer(0), Color.white);

		BackgroundGenerator back = new UniColorBackgroundGenerator(new Integer(	150), new Integer(50), Color.white);

		FontGenerator font = new RandomFontGenerator(new Integer(30), new Integer(40),new Font[]{new Font("Arial",1,16)});

		WordToImage word2image = new DeformedComposedWordToImage(font, back, paster,rippleDefBack, cristalDef, rippleDef);

		addFactory(new GimpyFactory(words, word2image));

	}
}
